package org.yaac.server.egql;

import static com.google.common.base.Strings.isNullOrEmpty;

import java.io.Serializable;

import org.yaac.server.egql.evaluator.Evaluator;



/**
 * @author Max Zhu (thebbsky@gmail.com)
 *
 */
public class InsertItem implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String identity;
	
	private Evaluator e;
	
	private Boolean indexed;

	@SuppressWarnings("unused")
	private InsertItem(){}
	
	/**
	 * @param identity
	 * @param e
	 * @param indexed
	 */
	public InsertItem(String identity, Evaluator e, Boolean indexed) {
		super();
		this.identity = identity;
		this.e = e;
		this.indexed = indexed;
	}

	/**
	 * @param identity
	 * @param e
	 * @param indexed
	 */
	public InsertItem(String identity, Evaluator e, String indexed) {
		super();
		this.identity = identity;
		this.e = e;
		
		if (isNullOrEmpty(indexed)) {
			this.indexed = true;	// by default is true
		} else {
			this.indexed = Boolean.valueOf(indexed);
		}
	}

	public String getIdentity() {
		return identity;
	}

	public Evaluator getE() {
		return e;
	}

	public Boolean getIndexed() {
		return indexed;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((e == null) ? 0 : e.hashCode());
		result = prime * result + ((identity == null) ? 0 : identity.hashCode());
		result = prime * result + ((indexed == null) ? 0 : indexed.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		InsertItem other = (InsertItem) obj;
		if (e == null) {
			if (other.e != null)
				return false;
		} else if (!e.equals(other.e))
			return false;
		if (identity == null) {
			if (other.identity != null)
				return false;
		} else if (!identity.equals(other.identity))
			return false;
		if (indexed == null) {
			if (other.indexed != null)
				return false;
		} else if (!indexed.equals(other.indexed))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "InsertItem [identity=" + identity + ", e=" + e + ", indexed=" + indexed + "]";
	}
}
